<!-- DataTables CSS -->
<link href="<?=base_url('public')?>/bower_components/datatables-plugins/integration/bootstrap/3/dataTables.bootstrap.css" rel="stylesheet">

<!-- DataTables Responsive CSS -->
<link href="<?=base_url('public')?>/bower_components/datatables-responsive/css/dataTables.responsive.css" rel="stylesheet">

<style type="text/css">
    td span{
        color: red;
    }
</style>

<div id="page-wrapper">
            <div class="row">
                <div class="col-lg-12">
                    <h1 class="page-header">客户列表</h1>
                </div>
                <!-- /.col-lg-12 -->
            </div>
            <!-- /.row -->
            <div class="row">
                <div class="col-lg-12">
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            <a href="<?=site_url('customer/csv_result')?>" class="btn btn-primary" target="_blank">文档导出</a>
                        </div>

                        <!-- /.panel-heading -->
                        <div class="panel-body">
                            <div class="dataTable_wrapper">

                                <table class="table table-striped table-bordered table-hover" id="dataTables-example">
                                    <thead>
                                        <tr>
                                            <th>#序号</th>
                                            <th>录入时间</th>
                                            <th>客户名称</th>
                                            <?php if($_SESSION['user']['group'] == 1):?>
                                            <th>业务员</th>
                                            <?php endif;?>
                                            <th>手机号码</th>
                                            <th>地区</th>
                                            <th>客户类型</th>
                                            <th>客户级别</th>
                                            <th>客户来源</th>
                                            <th>最后更新</th>
                                            <th>管理</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?php foreach($list as $k => $v):?>
                                            <tr class="odd gradeX">
                                                <td><?=$v['id']?></td>
                                                <td class="center"><?=date('Y-m-d',$v['create_time'])?></td>
                                                <td><?=$v['cname']?></td>
                                                <?php if($_SESSION['user']['group'] == 1):?>
                                                <td><?=$v['user']['name']?></td>
                                                <?php endif;?>
                                                <td><?=$v['phone']?></td>
                                                <td class="center"><?=$v['address']?></td>
                                                <td class="center"><?=$v['ctype_name']?></td>
                                                <td><?=$v['crank_name']?></td>
                                                <td><?=$v['source_name']?></td>
                                                <td><?=$v['update_date']?></td>
                                                <td>
                                                    <?php if(!empty($v['beizhu'])):?>
                                                        <a href="javascript:;" onclick="open_view('<?=$v['beizhu']?>')">查看备注</a>
                                                    <?php endif;?>
                                                    <a href="<?=site_url('customer/c_update?cid='.$v['id'])?>">编辑</a>
                                                    <a href="javascript:;" onclick="c_delete('<?=$v['id']?>')">删除</a>
                                                </td>
                                            </tr>
                                        <?php endforeach;?>
                                    </tbody>

                                </table>

                            </div>
                        </div>
                        <!-- /.panel-body -->
                    </div>
                    <!-- /.panel -->
                </div>
                <!-- /.col-lg-12 -->
            </div>
            <!-- /.row -->
        </div>

<script src="<?=base_url('public')?>/bower_components/datatables/media/js/jquery.dataTables.min.js"></script>
<script src="<?=base_url('public')?>/bower_components/datatables-plugins/integration/bootstrap/3/dataTables.bootstrap.min.js"></script>
<script>
    $(document).ready(function() {
        $('#dataTables-example').DataTable({
                responsive: true
        });
    });

    function open_view(data){
        layer.open({
            type: 1,
            skin: 'layui-layer-rim', //加上边框
            area: ['620px', '440px'], //宽高
            title:'备注',
            content: '<p style="margin:15px">'+data+'</p>'
        });
    }

    //删除客户
    function c_delete(cid){
        layer.confirm("是否将该客户删除放入公海中？", {
            icon:0,
            btn: ['确定','取消'] //按钮
        }, function(){
            $.post("<?=site_url('customer/c_delete')?>",{cid:cid},function(data){
                if(data == 1){
                    layer.alert("操作成功！",{
                        icon:1,
                    },function(){
                        location.reload();
                    });
                }else{
                    layer.alert(data,{
                        icon:2,
                    });
                }
            });
        });
    }
</script>